<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
    <style>
      #app {
        font-family: Avenir, Helvetica, Arial, sans-serif;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-align: center;
        color: #2c3e50;
      }
    </style>
  </head>

  <body>
    <div id="app">
      <h1>大家好我叫:{{fullName}}</h1>
      <button @click="fullName='黄怡'">点击修改名字</button>
    </div>
    <script>
      Vue.config.productionTip = false;
      //实例化Vue
      const vm = new Vue({
        el: "#app",
        data() {
          return {
            firstName: "苏",
            lastName: "菲",
          };
        },
        computed: {
          fullName: {
            get() {
              return this.firstName + this.lastName;
            },
            set(val) {
              /* set函数中的参数就是计算属性被设置的值 */
              console.log(val);
              this.firstName = val.split("")[0];
              this.lastName = val.split("")[1];
              console.log(val.split("")[0]);
              console.log(val.split("")[1]);
            },
          },
        },
      });
    </script>
  </body>
</html>
